package com.tech.doggtv.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tech.doggtv.R;
import com.tech.doggtv.action.OnItemClickListener;

import java.io.File;

/**
 * @author jl_luo
 * @name: com.tech.doggtv.adapter
 * @description:
 * @date 2015/9/14 16:53
 */

public class ProgsAdapter extends RecyclerView.Adapter<ProgsAdapter.MyViewHolder>{
    private File[] mDatas;
    private OnItemClickListener itemClickListener;
    public ProgsAdapter( File[] mDatas){
        this.mDatas = mDatas;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                viewGroup.getContext()).inflate(R.layout.item_programs, viewGroup, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder myViewHolder, int i) {
        myViewHolder.tvName.setText(mDatas[i].getName());
        final int pos = i;
        myViewHolder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClickListener.onItemClick(view, pos);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDatas.length;
    }

    class MyViewHolder extends RecyclerView.ViewHolder
    {
        View root;
        TextView tvName;

        public MyViewHolder(View view)
        {
            super(view);
            tvName = (TextView) view.findViewById(R.id.tv_name);
            this.root = view;
        }
    }
    public void setItemClickListener(OnItemClickListener itemClickListener){
        this.itemClickListener = itemClickListener;
    }
}

